package com.xyht.sca_s.student_manage_system.modules.dormitory.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.dormitory.entity.req.SmsDormitoryTypeAddReq;
import com.xyht.sca_s.student_manage_system.modules.dormitory.entity.req.SmsDormitoryTypeDeletedReq;
import com.xyht.sca_s.student_manage_system.modules.dormitory.entity.req.SmsDormitoryTypeUpdateReq;
import com.xyht.sca_s.student_manage_system.modules.dormitory.service.SmsDormitoryTypeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 宿舍类型管理表 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2024-01-15
 */
@RestController
@RequestMapping("/dormitory/dormitoryType")
@SecretBody
public class SmsDormitoryTypeController {

    @Resource
    private JwtTokenUtil jwtTokenUtil;
    @Resource
    private SmsDormitoryTypeService smsDormitoryTypeService;

    @ApiOperation("添加宿舍类型")
    @PostMapping("/addDormitoryType")
    public ResponseResult addDormitoryType(HttpServletRequest request,@RequestBody SmsDormitoryTypeAddReq addReq){
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsDormitoryTypeService.addDormitoryType(addReq,userId);
    }

    @ApiOperation("删除宿舍类型")
    @PostMapping("/deletedDormitoryType")
    public ResponseResult deletedDormitoryType(@RequestBody SmsDormitoryTypeDeletedReq deletedReq){
        return smsDormitoryTypeService.deletedDormitoryType(deletedReq);
    }

    @ApiOperation("修改宿舍类型")
    @PostMapping("/updateDormitoryType")
    public ResponseResult updateDormitoryType(@RequestBody SmsDormitoryTypeUpdateReq updateReq){
        return smsDormitoryTypeService.updateDormitoryType(updateReq);
    }


    @ApiOperation("查看宿舍类型类别")
    @GetMapping("/getDormitoryTypeList")
    public ResponseResult getDormitoryTypeList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                               @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                               @RequestParam(value = "name", required = false) String name){
        return smsDormitoryTypeService.getDormitoryTypeList(pageNum,pageSize,name);
    }


}

